package com.libc.yygh.common;

/**
 * 提供一些对象有效性校验的方法
 *
 * @version 1.0<br>
 * @qualiFild nc.pub.itf.tools.pub.JudgeAssertUtil.java<br>
 * @author：licheng<br>
 * @date Created on 2019-8-12<br>
 */
public class JudgeAssertUtil
{
    public static String logSplitStr = "SB`";
    private static String fileDir = "thwlogs";

    /************************************************************* <br>
     *
     *说明: 斷言：最高法法官判斷<br>
     *
     * @Description   <br>
     * @Date Created on 2022/4/1  14:08  <br>
     * @param judge
     * @param message <br>
     * @return void  <br>
     * @Author LIBENCHENG
     * @version 1.0 <br>
     ************************************************************* <br>
     */
    public static void checkAssert(boolean judge, String message) throws RuntimeException
    { if (judge) { throwException(new RuntimeException(logSplitStr + message)); } }

    /************************************************************* <br>
     *
     *说明: 异常处理<br>
     *
     * @Description   <br>
     * @Date Created on 2022/6/10  22:48  <br>
     * @param e <br>
     * @return void  <br>
     * @Author LIBENCHENG
     * @version 1.0 <br>
     ************************************************************* <br>
     */
    private static void throwException(Throwable e)
    {
        String[] bcs = StringUtil.valueOfNull(e.getMessage()).split(logSplitStr);
        String msg = PubEnvUtil.getSize(bcs) > 1 ? e.getMessage().replace(bcs[0], PubEnvUtil.EMPTY)
                                                    .replace(logSplitStr, PubEnvUtil.EMPTY) : e.getMessage();
        // msg = msg.replace(logSplitStr, PubEnvUtil.EMPTY);
        LoggerUtil.getInstance().debug(e.getMessage() + LoggerUtil.CRLF + StringUtil.toString(e));
        LoggerUtil.getInstance(fileDir).error(e.getMessage() + LoggerUtil.CRLF + StringUtil.toString(e));
        throw new RuntimeException(msg);
    }

    public static void notNull(Object object, String message)
    { if (object == null) { throwException(new IllegalArgumentException(message)); } }
}
